import ReactDOM from "react-dom/client";
import MyTest from './views/MyTest'
import React from "react";

declare global {
    interface Window {
        onMainUnload: () => void
    }
}

const view = JSON.parse(window.sessionStorage.getItem('popup_view') ?? '{}')
console.log('view1', view)
const id = view?.['id']
const mainWinId = view?.['parentId']
if (window.opener && mainWinId) {
    console.log('-------- popup4 ----', view)
    if (!document.querySelector('.main')) window.document.body?.insertAdjacentHTML?.('beforeend', `<div class="main"></div>`)
    ReactDOM.createRoot(document.querySelector('.main')).render(<MyTest/>)

    window.onMainUnload = () => {
        setTimeout(() => {
            if (!window.opener) window.close()
        }, 300)
    }

    window.addEventListener('beforeunload', () => {
        window.opener.removePopup(id)
    })
}

export {}